package org.lgiavedoni.android.franq.command.system;

import org.apache.commons.cli.CommandLine;
import org.lgiavedoni.android.franq.core.command.Command;
import org.lgiavedoni.android.franq.core.service.Service;
import org.lgiavedoni.android.franq.core.service.ServiceManager;
import org.lgiavedoni.android.franq.service.communication.CommunicationService;
import org.lgiavedoni.android.franq.service.log.Logger;

public class RestartCommand extends Command {

	@Override
	public boolean execute(CommandLine cmd) throws Exception {
		for (Service s : ServiceManager.inst.getAllServices()) {
			if (s.isStarted()) {
				try {
					s.restart();
					CommunicationService.inst.sendDefaultTextMessage("Restarting service [" + s.getServiceName() + "]");
				} catch (Exception ex) {
					Logger.inst.error(ex);
				}
			}
		}
		return true;
	}

	@Override
	public String getCommandText() {
		return "restart";
	}
}